/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package za.ac.cput.kleintjes.favouritenumber.Impl;

import za.ac.cput.kleintjes.favouritenumber.FavouriteNumber;

/**
 * @author Administrator
 */
public class PCFavouriteNumberImpl implements FavouriteNumber{
    
    private int[] numbers;

    public PCFavouriteNumberImpl(int cycles) {
        genereateNumbers(cycles);
    }

    public PCFavouriteNumberImpl() {
    }
    
    public void genereateNumbers(int cycles)
    {
        numbers = new int[10];
        int randomNumber;
        
        for(int x=0; x<cycles; x++)
        {
            randomNumber = (int)(Math.random()*10);
            for(int y=0; y<10; y++)
            {
                if(y == randomNumber)
                    numbers[y]++;
            }
        }
    }
    
    @Override
    public int showFavouriteNumber() {
        int post = 0;
        //System.out.println("Number: "+0+" is :"+numbers[0]);
        for(int y=1; y<10; y++)
        {
            if(numbers[y] > numbers[post])
                post = y;
        }   
        //System.out.println("Winning number is: "+post+" with :"+numbers[post]);
        
        return post;
    }    
}
